/*
 ============================================================================
 Page	     : 362-363
 Name        : mod_str.c
 Date        : 20210406
 Author      : Hbue 18060333
 Copyright   : Your copyright notice
 Description : 修改字符串
 ============================================================================
 */

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define LIMIT 81
void ToUpper(char *);
int PunctCount(const char *);

int main(void)
{
	char line[LIMIT];
	char *find =  NULL;

	puts("Please enter a line:");
	fgets(line, LIMIT, stdin);
	find = strchr(line, '\n');		// 查找换行符
	if(find)						// 如果地址不是NULL
	{
		*find = '\0';				// 用空字符替换
	}
	ToUpper(line);
	puts(line);
	printf("That line has %d punctuation characters.\n", PunctCount(line));

	return 0;
}

// 无聊
void ToUpper(char *string)
{
	while(*string)
	{
		*string = toupper(*string);
		string++;
	}
}

int PunctCount(const char *string)
{
	int count = 0;

	while(*string)
	{
		if(ispunct(*string))
		{
			count++;
		}
		string++;
	}

	return count;
}

